package org.learn.controller;

import org.learn.bean.PersonBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ThymeleafController {

    @GetMapping("/ThymeleafPage")
    public String ThymeleafPage(Model model){
        PersonBean personBean = new PersonBean();
        personBean.setName("hello");
        personBean.setPassword("password");
        personBean.setAddress("my address");
        personBean.setAge(10);

        List<PersonBean> personsList = new ArrayList<>();

        personsList.add(personBean);
        PersonBean personBean2 = new PersonBean();

        personBean2.setName("hello2");
        personBean2.setPassword("password2");
        personBean2.setAddress("my address2");
        personBean2.setAge(11);
        personsList.add(personBean2);

        PersonBean personBean3 = new PersonBean();

        personBean3.setName("hello3");
        personBean3.setPassword("password3");
        personBean3.setAddress("my address3");
        personBean3.setAge(12);
        personsList.add(personBean3);

        model.addAttribute("personBean",personBean); //Bean

        model.addAttribute("personsList",personsList);  //List


        model.addAttribute("hello","hello,thymeleaf");  //String

        return "thymeleafdemo";
    }
}
